/*  Game/Army Editor for yALB - Yet Another List Builder (roster Editor for Wargames/tabletop games).
    Copyright (C) 2008-2012  Daniel Ricardo Castro Alvarado

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

#ifndef ITEMWIDGET_H
#define ITEMWIDGET_H

#include <QWidget>
#include <QHash>

#include "collections/itemcollection.h"

#include "propertyform.h"
//#include "actionwidget.h"

class CategorizerModel;
class ItemSelector;

namespace Ui {
    class ItemWidget;
}

class ItemWidget : public QWidget
{
    Q_OBJECT

public:
    ItemWidget(ItemCollection *_items, CategorizerModel *_itemModel, ItemSelector& _itemSelector,
                        QWidget *parent = 0);
    ~ItemWidget();

    void clearItemForm();

public slots:

    void addProperty(const GameProperty& property, const QString &key);
    void updateProperty(const QString& oldKey, const GameProperty& newProperty,
                         const QString& newKey);
    void removeProperty(const QString& key);

    /*void addColumn(const Column &column, const QString &key);
    void updateColumn(const QString& oldKey, const Column& newColumn,
                         const QString& newKey);
    void removeColumn(const QString& key);*/

protected:
    void changeEvent(QEvent *event);

private slots:
    void currentItemChanged(const QModelIndex& current, const QModelIndex& previous);
    void on_itemAdd_clicked();
    void on_itemUpdate_clicked();
    void on_itemDelete_clicked();
    void on_itemClone_clicked();
    void on_itemSetPropertiesButton_clicked();

private:
    Ui::ItemWidget *ui;

    ItemCollection *items; // (Variable) pointer to const ItemCollection
    CategorizerModel *itemModel;

    PropertyForm propertyForm;
};

inline void ItemWidget::addProperty(const GameProperty &property, const QString &key) {
    propertyForm.addProperty(property, key);
}

inline void ItemWidget::updateProperty(const QString &oldKey, const GameProperty &newProperty,
                                         const QString &newKey) {
    propertyForm.updateProperty(oldKey, newProperty, newKey);
}

inline void ItemWidget::removeProperty(const QString &key) {
    propertyForm.removeProperty(key);
}

/*inline void ItemWidget::addColumn(const Column &column, const QString &key) {
    actionBox.addColumn(column, key);
}

inline void ItemWidget::updateColumn(const QString &oldKey, const Column &newColumn,
                                       const QString &newKey) {
    actionBox.updateColumn(oldKey, newColumn, newKey);
}

inline void ItemWidget::removeColumn(const QString &key) {
    actionBox.removeColumn(key);
}*/

#endif // ITEMWIDGET_H
